package com.supermap.authentication.main;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by xiaolu on 2017/10/13.
 */
public class TestMain {
    public static void main(String[] args) {
        String[] values = getValid(48);
        for (String value:values) {
            System.out.println(value);
        }
        System.out.println("++++++++");
        System.out.println(String.format("%04d",1));
        char s = 'A';
        System.out.println(((int) s));
        System.out.println(((char) 65));
        String city = "黑龙江省";
        city = city.substring(0, city.length() - 1);
        System.out.println(city);
        String path = System.getProperty("user.dir");
        String filePath = path + "/111.BCQ";
        try {
            FileInputStream inputStream = new FileInputStream(filePath);
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream,"UTF-8");
            BufferedReader reader = new BufferedReader(inputStreamReader);
            String sta = null;
            List ss = new ArrayList<String>();
            while ((sta = reader.readLine()) != null){
                if(!ss.contains(sta)){
                    ss.add(sta);
                }
                System.out.println(getUTCTime("DATE","2"));
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private static String[] getValid(int endValid){

        String valid = "";
        for(int i = 3; i <= endValid; i += 3){
            valid = valid + i;
            if(endValid != i) {
                valid += ",";
            }
        }
        return valid.split(",");
    }

    private static String getUTCTime(String timeType, String target) {
        //logger.debug("getUTCTime");
        Date dateNow = new Date();
        if(!target.endsWith("1")){
            dateNow.setHours(Integer.parseInt(target));
            dateNow.setMinutes(12);
        }
        SimpleDateFormat sss = new SimpleDateFormat("yyyyMMddHHmm");
        System.out.println("=============>date" + sss.format(dateNow));

        // 1、取得本地时间：
        java.util.Calendar cal = java.util.Calendar.getInstance();
        cal.setTime(dateNow);
        // 2、取得时间偏移量：
        int zoneOffset = cal.get(java.util.Calendar.ZONE_OFFSET);
        // 3、取得夏令时差：
        int dstOffset = cal.get(java.util.Calendar.DST_OFFSET);
        // 4、从本地时间里扣除这些差量，即可以取得UTC时间：
        cal.add(java.util.Calendar.MILLISECOND, -(zoneOffset + dstOffset));
        // 5、获取世界时间
        Date date = new Date(cal.getTimeInMillis());
        if(timeType.equals("DATE")){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
            return sdf.format(date);
        }
        if(timeType.equals("SINGLEDATE")){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
            return sdf.format(date);
        }
        SimpleDateFormat sdf = new SimpleDateFormat("ddHHmm");
        return sdf.format(date);
    }
}
